package com.fwtai.api.controller;

import com.fwtai.config.ConfigFile;
import com.fwtai.service.api.ApiBuyService;
import com.fwtai.tool.ToolClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 微信或支付宝支付
 * @作者 田应平
 * @版本 v1.0
 * @创建时间 2021-12-17 14:25
 * @QQ号码 444141300
 * @Email service@dwlai.com
 * @官网 http://www.fwtai.com
*/
@Api(tags = "购买进货商品,token选填",description = "购买|进货商品")
@RestController
@RequestMapping(ConfigFile.guest_v10 + "buy")
public class BuyController{

  private final ApiBuyService apiBuyService;

  public BuyController(final ApiBuyService apiBuyService){
    this.apiBuyService = apiBuyService;
  }

  @ApiOperation(value = "购买进货商品,token必填", notes = "提交金额并调起支付功能,下单前得先调用接口 /api/guest/v1.0/wechat/getInfo")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "openId", value = "当前登录绑定的微信openId", dataType = "String", paramType = "query",required = true),
    @ApiImplicitParam(name = "buyer_type", value = "购买类型（1是用户[消费者]购买{购物车}；2是直营店向区级购买；3区级向总公司购买）", dataType = "int", paramType = "query",required = true),
    @ApiImplicitParam(name = "storeId", value = "当buyer_type=1时才传值直营门店的主键kid", dataType = "String", paramType = "query",required = false),
    @ApiImplicitParam(name = "areaProxyUserId", value = "当buyer_type=2时才传区代理的用户id(goods_area.user_id)", dataType = "String", paramType = "query",required = false),
    @ApiImplicitParam(name = "goodsInfo", value = "格式:[{\"storeGoodsId(当buyer_type=1时取门店商品库存表的kid)\":\"12541\",\"areaGoodsId(当buyer_type=2时取区域库存表的kid)\":\"18412\",\"goodsId\":\"102410\",\"number\":5,\"category(区分是1按瓶购买还是2按件购买,消费者默认为1)\":1},{\"storeGoodsId\":\"12541\",\"areaGoodsId\":\"18412\",\"goodsId\":\"212422\",\"number\":10}]", dataType = "String", paramType = "query",required = true)
  })
  @PostMapping("/prePay")
  public void prePay(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiBuyService.prePay(request),response);
  }

  @ApiOperation(value = "活动商品购买,token必填", notes = "提交金额并调起支付功能,下单前得先调用接口 /api/guest/v1.0/wechat/getInfo")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "openId", value = "当前登录绑定的微信openId", dataType = "String", paramType = "query",required = true),
    @ApiImplicitParam(name = "buyer_type", value = "购买类型(buyer_type=1)", dataType = "int", paramType = "query",required = true),
    @ApiImplicitParam(name = "storeId", value = "直营门店的主键kid", dataType = "long", paramType = "query",required = true),
    @ApiImplicitParam(name = "activityId", value = "活动kid", dataType = "long", paramType = "query",required = true),
    @ApiImplicitParam(name = "goodsInfo", value = "json数组,数据格式:[{\"storeGoodsId(门店商品库存表的kid)\":\"12541\",\"goodsId\":\"102410\",\"number\":5}]", dataType = "String", paramType = "query",required = true)
  })
  @PostMapping("/addActivityOrder")
  public void addActivityOrder(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiBuyService.addActivityOrder(request),response);
  }

  @ApiOperation("使用积分账户购买商品(积分购买),token必填")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "buyer_type", value = "购买类型（2是直营店向区级购买；3区级向总公司购买）", dataType = "int", paramType = "query",required = true),
    @ApiImplicitParam(name = "areaProxyUserId", value = "当buyer_type=2时才传区代理的用户kid(goods_area.user_id),即收款人", dataType = "String", paramType = "query",required = false),
    @ApiImplicitParam(name = "goodsInfo", value = "格式:[{\"areaGoodsId(当buyer_type=2时取区域库存表的kid)\":\"18412\",\"goodsId\":\"102410\",\"number\":5,\"category(区分是1按瓶购买还是2按件购买,消费者默认为1)\":1},{\"areaGoodsId\":\"18412\",\"goodsId\":\"212422\",\"number\":10}]", dataType = "String", paramType = "query",required = true)
  })
  @PostMapping("/addIntegralBuy")
  public void addIntegralBuy(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiBuyService.addIntegralBuy(request),response);
  }

  @RequestMapping("/notifyPay")
  public void notifyPay(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiBuyService.notifyPay(request),response);
  }

  @RequestMapping("/activityUrl")
  public void activityUrl(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiBuyService.activityUrl(request),response);
  }
}